package com.example.my.shop.mybatis.controller;
import java.util.Date;


import com.example.my.shop.mybatis.entity.TbUser;
import com.example.my.shop.mybatis.service.TbUserService;
import com.example.my.shop.mybatis.service.impl.TbUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

 /**
  * @ProjectName:
  * @Package:        com.example.my.shop.mybatis.controller
  * @ClassName:      User_userSearchController
  * @Description:    模糊查询功能
  * @Author:         Mr.Vincent
  * @CreateDate:     2019/6/2 13:17
  * @Version:        1.0.0
  */
@WebServlet(value = "/userSearch")
public class User_userSearchController extends HttpServlet {

    /**
     * @Method:        service
     * @Description:    两种模糊查询功能
     * @Param:         [req, resp]
     * @return:        void
     * @Author:        Mr.Vincent
     * @Date:          2019/6/2
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String search = req.getParameter("search");
        String userName = req.getParameter("userName");
        String phone = req.getParameter("phone");
        String email = req.getParameter("email");

        TbUser tbUser = new TbUser();
        tbUser.setUserName(userName);
        tbUser.setPhone(phone);
        tbUser.setEmail(email);

        Map map = new HashMap();
        map.put("search", search);
        map.put("tbUser", tbUser);

        TbUserService tbUserService = new TbUserServiceImpl();
        List<TbUser> tbUsers = tbUserService.likeSearch(map);

        req.setAttribute("tbUsers",tbUsers);
        req.getRequestDispatcher("/user_list.jsp").forward(req,resp);

    }
}
